//
//  OderHeaderCell.m
//  PigMarket
//
//  Created by 张敬 on 2019/8/13.
//  Copyright © 2019年 pigmarket.oc. All rights reserved.
//

#import "OrderHeaderCell.h"

@interface OrderHeaderCell()

@end


@implementation OrderHeaderCell

- (void)setupUI
{
    [self addSubview:self.shopNameLab];
    [self addSubview:self.cleanBtn];
    [self addSubview:self.stateLab];
}


- (void)setupLayout
{
    {
        _shopNameLab.size = CGSizeMake(KScreenWidth - 120, 21);
        _shopNameLab.mj_x = 15;
        _shopNameLab.mj_y = 18;
    }
    
    {
        _stateLab.size = CGSizeMake(50, 18);
        _stateLab.mj_y = 18;
        
    }
    
    {
        _cleanBtn.size = CGSizeMake(40, 40);
        _cleanBtn.mj_y = 8;
        _cleanBtn.mj_x = KScreenWidth - 38;
    }
    
}


#pragma mark - setter methods

- (void)setShopName:(NSString *)shopName{
    
    _shopName = shopName;
    NSString *newStr = [NSString stringWithFormat:@"%@%@",@" ", shopName];
    NSMutableAttributedString *aims = [newStr createAttributingByIcon:@"meat_found_shopIcon" downIndexImage:@"meat_cart_enter" textColor:UIColorFromRGB(0x333333) font:mMediumFont(17)];
    _shopNameLab.attributedText = aims;
}

- (void)setOrderStateType:(OrderStateType)orderStateType{
    
    UIColor *aimsColor = UIColorFromRGB(0xF25C62);
    UIColor *nomalColor = UIColorFromRGB(0x7E7E7E);
    CGFloat w = KScreenWidth - 30;
    
    switch (orderStateType) {
        case OrderStateTyp_NoPaying: //待付款
            {
                _cleanBtn.hidden = YES;
                _stateLab.textColor = aimsColor;
                _stateLab.text = @"待付款";
                _stateLab.mj_x = w - _stateLab.width - 15;
            }
            break;
            
        case OrderStateType_NoSending: //待配送
            {
                _cleanBtn.hidden = YES;
                _stateLab.textColor = aimsColor;
                _stateLab.text = @"待发货";
                _stateLab.mj_x = w - _stateLab.width - 15;
            }
            break;
        
        case OrderStateType_NoAccept: //待收货
        {
            _cleanBtn.hidden = YES;
            _stateLab.textColor = aimsColor;
            _stateLab.text = @"待收货";
            _stateLab.mj_x = w - _stateLab.width - 15;
        }
            break;


        case OrderStateType_NoEvaluation: //待评价
            {
                _cleanBtn.hidden = NO;
                _stateLab.textColor = aimsColor;
                _stateLab.text = @"已完成";
                _stateLab.mj_x = w - _stateLab.width - 36;
            }
            break;

        case OrderStateType_Cancel: //已取消
            {
                _cleanBtn.hidden = YES;
                _stateLab.textColor = nomalColor;
                _stateLab.text = @"已取消";
                _stateLab.mj_x = w - _stateLab.width - 36;
            }
            break;

            
        default: //已完成
            {
                _cleanBtn.hidden = YES;
                _stateLab.textColor = aimsColor;
                _stateLab.text = @"已完成";
                _stateLab.mj_x = w - _stateLab.width - 36;
            }
            break;
    }
}


#pragma mark - getter methods

- (UILabel *)shopNameLab{
    if (!_shopNameLab) {
        _shopNameLab = [[UILabel alloc] init];
    }
    return _shopNameLab;
}


- (UILabel *)stateLab{
    if (!_stateLab) {
        _stateLab = [[UILabel alloc] init];
        _stateLab.font = mFont(13);
        _stateLab.textAlignment = NSTextAlignmentRight;
    }
    return _stateLab;
}


- (UIButton *)cleanBtn{
    
    if (!_cleanBtn) {
        _cleanBtn = [UIButton makeButtonWithImageName:@"meat_shopcart_cancel"];
        _cleanBtn.hidden = YES;
        
        @weakify(self);
        _cleanBtn.tapBlock = ^{
            @strongify(self);
            if (self.dealCleanOrderBlock) {
                self.dealCleanOrderBlock();
            }
        };
    }
    return _cleanBtn;
}


@end
